﻿using System.Threading.Tasks;

namespace Sidvall.Security
{
    public class IdentityAuthorizationProviderFactory : Sidvall.Reflection.IInstanceItemFactory<IAuthorizationProvider>
    {
        #region Public Members

        #region CreateAsync

        public async Task<IAuthorizationProvider> CreateAsync(string context)
        {
            var item = new IdentityAuthorizationProvider();
            var instanceItems = Sidvall.Reflection.InstanceItemCollection.Deserialize(context, new Sidvall.Reflection.InstanceItemCollection());
            var userValidators = await Sidvall.SystemContext.Current.CodeManager.CreateInstancesAsync<IIdentityValidator>(instanceItems).ConfigureAwait(false);
            item.Validators.AddRange(userValidators);
            return await Task.FromResult(item).ConfigureAwait(false);
        }

        #endregion

        #endregion
    }
}
